<template>
  <div>
    <!-- 面包屑导航区 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>课程管理</el-breadcrumb-item>
      <el-breadcrumb-item>教师课程管理</el-breadcrumb-item>
    </el-breadcrumb>
    <!-- 卡片视图 -->
    <el-card>
      <!-- 搜索 添加 -->
      <el-row :gutter="20">
        <el-col :span="6">
          <el-input placeholder="请输入内容" v-model="queryInfo.query" clearable @clear="getTeacherClass">
            <el-button slot="append" icon="el-icon-search" @click="getTeacherClass"></el-button>
          </el-input>
        </el-col>
<!--        <el-col :span="4">-->
<!--          <el-button type="primary" @click="addDialogVisible = true">添加用户</el-button>-->
<!--        </el-col>-->
      </el-row>
      <!-- 用户列表区域 -->
      <el-table :data="teacherList" border stripe>
        <!-- stripe: 斑马条纹
        border：边框-->
        <el-table-column type="index" label="#"></el-table-column>
        <el-table-column prop="teacherName" label="姓名"></el-table-column>
        <el-table-column prop="teacherId" label="职工号"></el-table-column>
        <el-table-column label="课程" prop="course">
<!--          <template  slot-scope="scope">-->
<!--            <el-button type="primary" @click="checkDetail(scope.row)">查看课表</el-button>-->
<!--          </template>-->
          <template  slot-scope="scope">
            <el-button type="primary" @click="checkDetail(scope.row)">查看课表</el-button>
          </template>
        </el-table-column>
      </el-table>
      <!-- 分页区域 -->
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="queryInfo.pagenum"
        :page-sizes="[2, 5, 10, 15]"
        :page-size="queryInfo.pagesize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="totle"
      ></el-pagination>
    </el-card>
    <!-- 课表弹框区域 -->
    <el-dialog
      title="课表"
      :visible.sync="dialogVisible"
      width="80%"
      v-if="dialogVisible"
      class="teacherClass-dialog"
    >
      <span>姓名:{{name}}</span>
      <span>职工号:{{id}}</span>
      <TimeTable></TimeTable>
      <span slot="footer" class="dialog-footer">
        <el-button @click="closeDialog">取 消</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import * as mockApi from '../../api/api.js'
import TimeTable from "./Timetable/TimeTable.vue"

export default {
  data (){
    return {
      //教师列表
      teacherList: [],
      //教师课表
      teacherclasss: [],
      totle: 0,
      //当前所选行
      row:[],
      //对话框
      dialogVisible: false,
      //查看课程
      //课程列表
      classs:[],
      id:'',
      name:'',

      // 获取用户列表查询参数对象
      queryInfo: {
        query: '',
        // 当前页数
        pagenum: 1,
        // 每页显示多少数据
        pagesize: 5
      },
      // 所有角色数据列表
      rolesLsit: [],
      // 已选中的角色Id值
      selectRoleId: ''
    }
  },

  created () {
    this.getTeacherClass()
  },

  components: {
    TimeTable
  },

  methods: {
      async getTeacherClass() {
        mockApi.getTeacherClass().then(res => {
          if (res.meta.status !== 200) return this.$message.error(res.meta.msg)
          // console.log(res)
          this.teacherList = res.data.teachers
          this.totle = res.data.totle
          this.teacherclasss = res.data.teachers.teacherclasss
        })
      },


    //获取当前行数据并跳转到课表页面
    checkDetail(val){
      this.dialogVisible = true
      this.name = val.teacherName
      this.id = val.teacherId
      this.$store.dispatch("setTeacherClassList",val.teacherclasss)
    },

    //关闭弹框
    closeDialog(){
      this.dialogVisible = false
    },

    // 监听 pagesize改变的事件
    handleSizeChange (newSize) {
      // console.log(newSize)
      this.queryInfo.pagesize = newSize
      this.getTeacherClass()
    },

    // 监听 页码值 改变事件
    handleCurrentChange (newSize) {
      // console.log(newSize)
      this.queryInfo.pagenum = newSize
      this.getTeacherClass()
    },
  }
}

</script>

<style lang="less" scoped>
.teacherClass-dialog{
  span{
    margin-left: 20px;
    font-size: 18px;
  }
}
</style>
